<?php
	include "core/mysql.php";
	$name = $_GET['name'];
    $pass = $_GET['pass'];
    $shuoshuo = $_GET['shuoshuo'];
    $email = $_GET['email'];
   $touxiang = $_GET['touxiang'];
	
	//1、做好数据的校验
 $arr = array();
 //判断是否输入用户名
  if(empty($_GET['name'])){
	 $arr['code'] = -10001;
	 $arr['message'] = "请输入用户名";	
	 echo json_encode($arr);
	 exit();
 }
 //判断是否输入密码
 if(empty($_GET['pass'])){
	 $arr['code'] = -10002;
	 $arr['message'] = "请输入密码";	
	 echo json_encode($arr);
	 exit();
 }
 //判断密码长度是不是6位
 if(strlen($pass)<6){//检测用户密码的长度是否小于6
    	$arr['code'] = -1003;
	    $arr['message'] = "用户密码的长度不得少于6位!请重新输入！";	
	    echo json_encode($arr);
	    exit();
    }
 //判断是否填写个性签名
if(empty($_GET['shuoshuo'])){
	 $arr['code'] = -10004;
	 $arr['message'] = "请填写个性签名！";	
	 echo json_encode($arr);
	 exit();
 }
 
 //判断是否填写邮箱
if(empty($_GET['email'])){
	 $arr['code'] = -10005;
	 $arr['message'] = "请填写邮箱！";	
	 echo json_encode($arr);
	 exit();
   }
  
 //判断邮箱格式
  $checkmail="/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/";//定义正则表达式                        
        if(preg_match($checkmail,$email)){                 //用正则表达式函数进行判断              
        }else{
        	$arr['code'] = -10006;
	        $arr['message'] = "对不起,电子邮箱格式不正确";	
	        echo json_encode($arr);
	        exit();  
        }  
 

//2、获取到页面传过来的用户名、密码

$sqlname = "select * from tbl_user where `name` = '$name' ";
//3、把用户、密码和年龄组成一条可以插入的SQL语句
$sql = "INSERT INTO tbl_user(`name`,password,string,email,touxiang_img) VALUES('{$name}','{$pass}','{$shuoshuo}','{$email}','{$touxiang}')";

//封装连接数据库
connect();

$resname = mysqli_query($link, $sqlname);
if(mysqli_num_rows($resname)>0){
				$arr['code'] = -10007;
				$arr['message'] = "对不起,用户名已存在";	
				echo json_encode($arr);
	}else{

//5、执行插入语句
$res = mysqli_query($link, $sql);
//判断影响的行数是不是大于0
if(mysqli_affected_rows($link)>0){
	
	//6、提醒用户注册成功
	$arr['code'] = 1;
	$arr['message'] = "恭喜您!注册成功";	
	echo json_encode($arr);
}else{
	$arr['code'] = -10008;
	$arr['message'] = "对不起,注册失败";	
	echo json_encode($arr);
}

}

//7、关闭数据库
mysqli_close($link);
